package com.czm.art_light.constant;


import com.czm.art_light.exception.BusinessException;
import lombok.Getter;

/**
 * 通用常量
 */
public class CommonConsts {
    /**
     * 图片验证的最大的错误次数3次
     */
    public static final String IMG_VERIFY_CODE_ERROR_NUMBER = "3";

    /**
     * 图片验证码的过期时间5分钟
     */
    public static final Integer IMG_VERIFY_CODE_EXPIRATION_TIME = 5;

    /**
     * 默认锁等待超时时间（秒） 5秒
     */
    public static final long LOCK_WAIT_TIME = 5;

    /**
     * 默认锁的释放时间 30秒
     */
    public static final long LOCK_LEASE_TIME = 30;

    /**
     * 默认正常数据缓存时间（秒） 60 * 5
     */
    public static final long DEFAULT_CACHE_EXPIRATION_TIME = 60 * 5;

    /**
     * 默认空值缓存时间（秒）60
     */
    public static final long DEFAULT_EMPTY_CACHE_EXPIRATION_TIME = 60;

    /**
     * 流派信息 缓存时间 8天
     */
    public static final long MOVEMENT_CACHE_EXPIRATION_TIME = 60 * 60 * 24 * 8;

    /**
     * 艺术家信息 缓存时间 3天
     */
    public static final long ARTIST_CACHE_EXPIRATION_TIME = 60 * 60 * 24 * 3;

    /**
     * 艺术作品信息 缓存时间 18天
     */
    public static final long WORK_CACHE_EXPIRATION_TIME = 60 * 60 * 24 * 18;

    /**
     * 话题信息 缓存时间 5天
     */
    public static final long TOPIC_CACHE_EXPIRATION_TIME = 60 * 60 * 24 * 5;

    /**
     * 类别信息 缓存时间 6天
     */
    public static final long CATEGORY_CACHE_EXPIRATION_TIME = 60 * 60 * 24 * 6;

    /**
     * 反馈类型内容 缓存时间 30天
     */
    public static final long FEEDBACK_TYPE_CACHE_EXPIRATION_TIME = 60 * 60 * 24 * 30;

    /**
     * 帮助内容 缓存时间 20天
     */
    public static final long HELP_CACHE_EXPIRATION_TIME = 60 * 60 * 24 * 20;


    /**
     * 默认添加到elasticsearch的超时时间
     */
    public static final String ELASTICSEARCH_ADD_TIMEOUT = "10s";


    /**
     * 艺术图片缓存头 expires
     */
    public static final String CACHE_EXPIRES = "expires";

    /**
     * 是
     */
    public static final Integer YES = 1;
    public static final String TRUE = "true";


    /**
     * 否
     */
    public static final Integer NO = 0;
    public static final String FALSE = "false";


    /**
     * 网站请求的前缀字符'/'
     */
    public static final char URL_PATH_PRE = '/';

    /**
     * windows创建目录的前缀字符'/'
     */
    public static final char WINDOWS_FILE_PATH_PRE = '\\';

    /**
     * linux创建目录的前缀字符'/'
     */
    public static final char LINUX_FILE_PATH_PRE = '/';

    /**
     * 微信头像文件默认后缀
     */
    public static final String WECHAT_AVATAR_FILE_DEFAULT_POSTFIX = ".jpg";

    /**
     * 微信头像文件限制10MB
     */
    public static final long WECHAT_AVATAR_FILE_LIMIT_SIZE = 10 * 1024 * 1024;

    /**
     * 微信头像文件默认JPEG格式 contentType = "image/jpeg"
     */
    public static final String WECHAT_AVATAR_FILE_DEFAULT_CONTENT_TYPE = "image/jpeg";

    /**
     * 统计数量初始化为0
     */
    public static final Long STATISTICS_COUNT_INIT = 0L;

    /**
     * 用户行为类型 view-点击、download-下载、share-分享、
     */
    public enum ActionType {
        /**
         * 点击
         */
        VIEW("view"),
        /**
         * 下载
         */
        DOWNLOAD("download"),
        /**
         * 分享
         */
        SHARE("share"),
        /**
         * 喜欢
         */
        LIKE("like"),
        /**
         * 不喜欢
         */
        DISLIKE("dislike");


        private final String value;

        ActionType(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public static ActionType fromValue(String value) {
            for (ActionType type : ActionType.values()) {
                if (type.getValue().equalsIgnoreCase(value)) {
                    return type;
                }
            }
            throw new BusinessException(ArtErrorCodeEnum.VALUE_NOT_Enum);
        }
    }
    /**
     * 喜欢状态常量
     */
    @Getter
    public enum LikeStatus {
        LIKE(1, "喜欢"),
        DISLIKE(0, "不喜欢");

        private final int value;       // 数据库存储的值
        private final String description; // 对应的描述

        LikeStatus(int value, String description) {
            this.value = value;
            this.description = description;
        }

        public static LikeStatus fromValue(int value) {
            for (LikeStatus status : LikeStatus.values()) {
                if (status.getValue() == value) {
                    return status;
                }
            }
            throw new BusinessException(ArtErrorCodeEnum.VALUE_NOT_Enum);
        }
    }
    /**
     * 性别常量
     */
    public enum SexEnum {

        /**
         * 男
         */
        MALE(0, "男"),

        /**
         * 女
         */
        FEMALE(1, "女");

        SexEnum(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        private int code;
        private String desc;

        public int getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

    }

    /**
     * 评论审核常量  审核状态;0-待审核 1-审核通过 2-审核不通过
     */
    public enum commentModerationEnum {

        /**
         * 0-待审核
         */
        AUDIT_STATUS_PENDING(0, "评论待审核"),

        /**
         * 1-审核通过
         */
        AUDIT_STATUS_APPROVED(1, "评论审核通过"),

        /**
         * 2-审核不通过
         */
        AUDIT_STATUS_REJECTED(2, "评论审核不通过");

        commentModerationEnum(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        private final int code;
        private final String desc;

        public int getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }

    }

    /**
     * 反馈状态（0: 未处理, 1: 处理中, 2: 已处理）
     */
    public enum FeedbackStatusEnum {
        UNPROCESSED(0, "未处理"),
        PROCESSING(1, "处理中"),
        PROCESSED(2, "已处理");
        FeedbackStatusEnum(int code, String desc) {
            this.code = code;
            this.desc = desc;
        }
        private final int code;
        private final String desc;
        public int getCode() {
            return code;
        }
        public String getDesc() {
            return desc;
        }
    }

    /**
     * 责任链的排序数值
     */
    public enum ChainSortEnum {
        SORT_1(1),
        SORT_2(2),
        SORT_3(3),
        SORT_4(4),
        SORT_5(5);
        ChainSortEnum(int sort) {
            this.sort = sort;
        }

        public Integer getSort() {
            return sort;
        }

        private final int sort;
    }
}
